﻿      function NewsClassAdd()
      {
        var name=$('#name').val();
        var read=$('#readme').val();
        var returnstr;
        $.ajax({
        async:false,
        url:'../API/A_Newsclass.aspx',
        type:'POST',
        data:{edit:'add',classname:name,readme:read},
        success:function(msg)
        {
          returnstr=msg
        }
        });
        return returnstr;
      }
      function NewsClassList()
      {
        $.ajax({
         async:false,
         url:'../API/A_Newsclass.aspx',
         type:'POST',
         data:{edit:'list'},
         success:function(msg)
         {
           $("#list tbody").text("");
           $('#list tbody').append(msg);
         }
        })
      }

      $(document).ready(function(){NewsClassList();});
      $(function(){

            $("#dialog-form").dialog("destory"); 
            var name = $( "#name" ),
				readme = $( "#readme" ),
				allFields = $( [] ).add( name ).add( readme ),
				tips = $( ".validateTips" );
            function updateTips(t)
            {
              tips.text(t)	
                  .addClass("ui-state-highlight");
              setTimeout(function(){
                  tips.removeClass("ui-state-highlight",1500);
              },500);
            }
            function checkEmpty(e,n)
            {
              if(e.val().length>0){
                 return true;}
              else{
                 e.addClass("ui-state-error");
                 updateTips(n+"不能为空.");
                 return false;
                 }
            }
            $("#dialog-form").dialog({
                        autoOpen:false,
                        height:270,
                        width:350,
                        modal:true,
                        buttons:{
                                 "提交":function(){
                                       var flag=true;
                                       allFields.removeClass("ui-state-error");
                                       
                                       flag=flag && checkEmpty(name,"类别名称");
                                       flag=flag && checkEmpty(readme,"类别描述");
                                       
                                       if(flag)
                                       {
                                         var addFlag=NewsClassAdd();
                                         
                                         if(addFlag=="true")
                                         {
                                         	NewsClassList();
                                         	$(this).dialog("close");
                                         }
                                         else{
                                            name.addClass("ui-state-error");
                                         	updateTips("此类别名称以存在.")
                                         }
                                       }
                                 },
                                 "取消":function(){$(this).dialog("close");},
                                 },
                               close:function(){allFields.val("").removeClass("ui-state-error");},
               });
               $("#create-user").button().click(function(){$("#dialog-form").dialog("open");});
      });
      //列表 checkbox demo
var tt;
function aa()
{
  var c=$("input:checked");
  var b=new Array();
  for(var i=0;i<c.length;i++)
  {
    b[i]=c[i].value;
  }
  if(b.length>0)
  {
  $.ajax({
          async:false,
          url:'../API/A_Newsclass.aspx',
          type:'POST',
          data:{edit:"del",columnId:b},
          success:function(msg)
          {
            NewsClassList();
            alert(msg);
          }
  })
  }
  else
  {
   alert("先选择！");
  }
}
function bb()
{
$("input:checkbox").attr("checked",true)
}
function cc()
{
$("input:checkbox").removeAttr("checked");
}
function dd(id,type)
{
 switch(type)
 {
    case "save":
    {
      var classid=$("#"+id).parent().parent().attr("id");
      var classname=$("#div"+classid+" input:text").val();
      var classreadme=$("#divr"+classid+" input:text").val();
      $.ajax({
             async:false,
             url:"../API/A_Newsclass.aspx",
             type:"POST",
             data:{edit:"update",classid:classid,classname:classname,readme:classreadme},
             sueecss:function(msg)
             {
               alert(msg);
             }
      })
      break;
    }
    case "esc":
    {
      $("#"+id+" input:text").val(tt);
      break;
    }
 }
 $("#"+id+" input:text").attr("readonly",true);
 $("#"+id+" input:text").removeClass("textu").addClass("tableinput");
 $("#"+id+" a").hide();
   $("div a.aclass").removeClass("hidea");
}
function ee(id)
{ 
 tt=$("#"+id+" input:text").val();
 $("#"+id+" input:text").removeAttr("readonly");
 $("#div"+id).removeAttr("onmouseover");
 $("#"+id+" input:text").removeClass("tableinput").addClass("textu");
 $("#"+id+" a").show();
 $("div a.aclass").hide();
}
$(function(){$("td div").mouseover(function(){var ccc=$(this).attr("id");ff(ccc);})})
$(function(){$("td div").mouseout(function(){var ccc=$(this).attr("id");gg(ccc);})})
$(function(){$("div a.aclass").click(function(){var ccc=$(this).parent().attr("id");ee(ccc);})})
$(function(){$("div a.aaclass").click(function(){var ccc=$(this).parent().attr("id");var ddd=$(this).attr("title");dd(ccc,ddd);})})
function ff(id){$("#"+id+" a.aclass").show();}
function gg(id){$("#"+id+" a.aclass").hide();}